package com.jianyun.jyzs.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jianyun.jyzs.R;


public class IconTextView extends LinearLayout {

    private ImageView itvIcon;
    private TextView itvText;

    public IconTextView(Context context) {
        super(context);
        initView(null);
    }

    public IconTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(attrs);
    }

    private void initView(AttributeSet attrs) {
        inflate(getContext(), R.layout.rce_icon_text_view_item, this);
        itvIcon = (ImageView) findViewById(R.id.iv_itv_icon);
        itvText = (TextView) findViewById(R.id.tv_itv_text);
        if (attrs != null) {
            TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.IconTextView);
            Drawable drawable = attributes.getDrawable(R.styleable.IconTextView_itv_icon);
            CharSequence text = attributes.getString(R.styleable.IconTextView_itv_text);
            boolean enabled = attributes.getBoolean(R.styleable.IconTextView_itv_enabled, true);
            if (!enabled) {
                setEnabled(enabled);
            }
            itvIcon.setImageDrawable(drawable);
            itvText.setText(text);
            attributes.recycle();
        }
    }

    public void setEnabled(boolean enable) {
        itvIcon.setEnabled(enable);
        if (enable) {
            itvText.setTextColor(getResources().getColor(R.color.color_normal_text));
        } else {
            itvText.setTextColor(getResources().getColor(R.color.color_text_operation_disable));
        }
    }
}
